package com.xinchao.ck_mips.view;

import android.os.Bundle;

import com.orhanobut.logger.Logger;
import com.xinchao.ck_mips.R;
import com.xinchao.ck_mips.base.MvpActivity;
import com.xinchao.ck_mips.contract.MainContract;
import com.xinchao.ck_mips.presenter.MainPresenter;
import com.xinchao.ck_mips.widgets.WheelPlayView;

public class MainActivity extends MvpActivity<MainContract.Presenter> implements MainContract.View {

    private WheelPlayView mWheelPlayView;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void onCreatePresenter(Bundle savedInstanceState) {
       // FileUtils.copyVideoToCache(this, CK.DIR_PATH, CK.VIDEO_PATH);
        /*mWheelPlayView = findViewById(R.id.wheelPlay);

        ArrayList<WheelPlayView.Source> list = new ArrayList<>();
        WheelPlayView.Source source1 = new WheelPlayView.Source();
        //  source1.setFilePath(CK.VIDEO_PATH[0]);
        source1.setIndex(0);
        source1.setPlay_time(getVideoTime(source1.getFilePath()));
        source1.setType(WheelPlayView.FILE_TYPE_VIDEO);
        list.add(source1);

        WheelPlayView.Source source2 = new WheelPlayView.Source();
        //  source2.setFilePath(CK.VIDEO_PATH[1]);
        source2.setIndex(2);
        source2.setPlay_time(getVideoTime(source2.getFilePath()));
        source2.setType(WheelPlayView.FILE_TYPE_VIDEO);
        list.add(source2);

        WheelPlayView.Source source3 = new WheelPlayView.Source();
        //  source3.setFilePath(CK.VIDEO_PATH[2]);
        source3.setIndex(3);
        source3.setPlay_time(4000);
        source3.setType(WheelPlayView.FILE_TYPE_JPEG);
        list.add(source3);

        WheelPlayView.Source source4 = new WheelPlayView.Source();
        //  source4.setFilePath(CK.VIDEO_PATH[3]);
        source4.setIndex(1);
        source4.setPlay_time(4000);
        source4.setType(WheelPlayView.FILE_TYPE_JPEG);
        list.add(source4);

        mWheelPlayView.setSources(list);
        mWheelPlayView.start(this);*/
       /* String url = "https://obs-ck.obs.cn-east-2.myhwclouds.com/ckips/file/video/顾家功能“有颜任性” 0612.1.mp4";
        SourceInfoBean sourceBean = new SourceInfoBean();
        sourceBean.setProgramVersion("a4387bc4fe594b55a6a1854eec3d51b9");
        sourceBean.setFileName("顾家功能“有颜任性”0612");
        sourceBean.setUrl(url);
        SingleDownload.getInstance().downSingleFile(url, FileUtils.getProgramFilePath(sourceBean), new IDownCallbackListener() {
            @Override
            public void completed(String tag) {
                Log.v("xika", "下载完成");
            }

            @Override
            public void error(String url, Throwable t) {
                Log.v("xika", t.getMessage() + "error");
            }

            @Override
            public void progressed() {
                Log.v("xika", "下载中...");
            }

            @Override
            public void pending() {
                Log.v("xika", "开始下载");
            }
        });*/
    }

    @Override
    protected MainContract.Presenter createPresenter() {
        return new MainPresenter(this);
    }

    //取得视频真实长度
    private long getVideoTime(String videoPath) {

        android.media.MediaMetadataRetriever mmr = new android.media.MediaMetadataRetriever();

        try {
            mmr.setDataSource(videoPath);
            String duration = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_DURATION);
            return Long.parseLong(duration);
        } catch (Exception e) {
            Logger.t("video time").e("解析视频文件长度出错:" + videoPath);
            return 0;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();
        // mWheelPlayView.pause();
    }

    @Override
    public void onBackPressed() {
    }

}
